package com.fll.fangyicommon.exception;

import com.aliyun.oss.ServiceException;
import com.fll.fangyicommon.entity.ResultOk;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author fll
 * @create 2023/3/2
 */
@Slf4j
@RestControllerAdvice
public class GlobleException {


//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    @ExceptionHandler(value = RuntimeException.class)
//    public ResultOk exception(RuntimeException e){
//        ResultOk<String> ok = new ResultOk<>();
//        ok.setMsg("系统运行时异常");
//        log.error("系统运行时异常===>{}", e.getMessage());
//        e.printStackTrace();
//        return ok;
//    }

    //业务异常
    @ExceptionHandler(value = ServiceException.class)
    public ResultOk handleServiceException(ServiceException e) {
        ResultOk<String> ok = new ResultOk<>();
        ok.setCode(503);
        ok.setMsg("业务异常，开始事务处理");
        log.error("业务异常，开始事务处理===>{}", e.getMessage());
        e.printStackTrace();
        return ok;
    }

}